/**
 *
 * @ClassName: api.js
 * @Description: 请求API
 * @author acai
 * @date 2018年9月7日 下午1:20:55
 *
 */
import request from './request.js';
import helper from '../common/helper.js'
const url = '123123';
class api {

	constructor(options) {
		this._baseUrl = 'https://www.middol.com/proxy247/9991/microservice'
		// this._baseUrl = 'http://192.168.30.187:9991'
		this._docUrl = '';
		this.imgUrl = this._baseUrl;
		this._header = {
			'content-type': 'application/x-www-form-urlencoded'
		}
		this._request = new request()
	}
	/**
	 * 测试API
	 */
	loginBanner(data) {
		return this._request.postRequest(this._baseUrl + '/api/oauth/login/authorizeUrl', data).then(res => res
			.data)
	}
	userlogin(data) {
		uni.setStorageSync('loginData', data)
		return this._request.postRequest(this._baseUrl + '/auth/api/login', data).then(res => res.data)
	}
	//上传图片
	uploadImages(url, imgSrc, name, data, cb) {
		var that = this;
		uni.uploadFile({
			url: that._baseUrl + url, //仅为示例，非真实的接口地址
			filePath: imgSrc,
			name: name,
			formData: data,
			header: {
				Authorization: helper.token
			},
			success: (res) => {
				return typeof cb == "function" && cb(JSON.parse(res.data))
			},
			fail(fail) {
				return typeof cb == "function" && cb(false)
			}
		});
	}
	//报修流程提交操作
	async generateSignedUrl(data) {
		let heard = {
			Authorization: helper.token
		}
		return this._request.postRequest(this._baseUrl + '/oss/api/ossUploadRecord/list', data, heard)
			.then(res => res.data)
	}

	//封装通用方法
	//

	getAPI(url, key) {
		let heard = {
			Authorization: helper.token
		}
		return this._request.getRequest(this._baseUrl + url + key, {}, heard).then(res => res.data)
	}

	postAPI(url, data) {
		let heard = {
			Authorization: helper.token
		}
		return this._request.postRequest(this._baseUrl + url, data, heard).then(res => res.data)
	}

	deleteAPI(url, key) {
		let heard = {
			Authorization: helper.token
		}
		return this._request.deleteRequest(this._baseUrl + url + key, {}, heard).then(res => res.data)
	}

	putAPI(url, data) {
		let heard = {
			Authorization: helper.token
		}
		return this._request.putRequest(this._baseUrl + url, data, heard).then(res => res.data)
	}

}
export default api